#
# Rootfs auto dependency generating script
#

FOLDER?= $(shell basename $(shell pwd))/
COPY_FILE_TARGET=copy_file

.PHONY:	$(COPY_FILE_TARGET) clean all

all: $(COPY_FILE_TARGET)
ifdef FS_USR_CMD
	$(FS_USR_CMD)
endif
ifdef FS_COPY_DRIVER_CMD
	$(FS_COPY_DRIVER_CMD)
endif


ifneq ($(MAKECMDGOALS), clean)
ifeq ($(FILE_LIST), )
$(error Error FILE_LIST is empty!)
endif
endif

ifeq ($(strip $(TARGET_BASE_FOLDER)), )
$(error Error TARGET_BASE_FOLDER is empty!)
endif

#$(warning $(FILE_LIST) $(TARGET_BASE_FOLDER) $(FOLDER))

$(DEPEND_FILE_NAME): $(FILE_LIST) Makefile
	@$(RM)	$@
	@$(PRINTF) "$(COPY_FILE_TARGET):" >> $@; 
	@for x in $(FILE_LIST);	\
	do			\
		$(PRINTF) "%s " "$(TARGET_BASE_FOLDER)/$(FOLDER)/$$x" >> $@; \
	done
	@$(PRINTF) "\n\n" >> $@;

	@for x in $(FILE_LIST);	\
	do			\
		$(PRINTF) "%s\n" "$(TARGET_BASE_FOLDER)/$(FOLDER)/$$x : $$x" >> $@; \
		$(PRINTF) "\t%s\n" "$(MKDIR) -p $(TARGET_BASE_FOLDER)/$(FOLDER)/`dirname $$x`" >> $@; \
		$(PRINTF) "\t%s\n\n" "$(CP) $$x $(TARGET_BASE_FOLDER)/$(FOLDER)/`dirname $$x`" >> $@; \
	done

clean:
ifdef FS_USR_CLEAN_CMD
	$(FS_USR_CLEAN_CMD)
endif
	@$(RM) $(MAKE_LOG_FILE)
	@$(RM) $(DEPEND_FILE_NAME)
	@$(RM) $(TARGET_BASE_FOLDER)/$(FOLDER)/

ifneq "$(MAKECMDGOALS)" "clean"
sinclude $(DEPEND_FILE_NAME)
endif

include $(BUILD_MK)

# vim:noet:sw=4:ts=4

